<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of login
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Myaccount extends MY_Controller {

    //put your code here

    function Myaccount() {
        parent :: __construct();
        $this->load->model('pickup_model');
        $this->load->model('location_model');
        $this->load->model('member_model');
        $this->load->model('management_model');
        $this->load->model('listing_model');
    }

//--Subha (28/08/2012)--/
    function index() {
        $id = intval($this->session->userdata('mem_id'));
        $data['member']['info'] = $this->member_model->get_member($id);
        $data['member']['listing'] = $this->member_model->get_member_listings($id);


        $this->template->title('Welcome', 'carz.com')
                ->set_partial('header', 'header/header')
                ->set_partial('footer', 'footer/footer')
                ->set_partial('customer_care', 'sidebar/customer_care')
                ->set_partial('social_share', 'sidebar/social_share')
                ->set_partial('search_reviews', 'sidebar/search_reviews')
                ->set_partial('recent_news', 'sidebar/recent_news')
                ->set_partial('recent_reviews', 'sidebar/recent_reviews')
                ->build('pages/member/myaccount', $data);
    }

//-- Delete Account()--//
    function delete($id) {
        $this->member_model->delete_account($id);
        redirect('');
    }

//-- Change Password (30/08/2012)-Subha --//
    function change_password() {
        $id = intval($this->session->userdata('mem_id'));
        $data['member']['info'] = $this->member_model->get_member($id);
        $data['member']['listing'] = $this->member_model->get_member_listings($id);

        $this->template->title('Welcome', 'carz.com')
                ->set_partial('header', 'header/header')
                ->set_partial('footer', 'footer/footer')
                ->set_partial('customer_care', 'sidebar/customer_care')
                ->set_partial('social_share', 'sidebar/social_share')
                ->set_partial('search_reviews', 'sidebar/search_reviews')
                ->set_partial('recent_news', 'sidebar/recent_news')
                ->set_partial('recent_reviews', 'sidebar/recent_reviews')
                ->build('pages/member/change_password', $data);
    }

//-- New Password Change Submit -----//
    function new_password_submit() {
        $this->form_validation->set_rules('old_pwd', 'Old Password', 'trim|required');
        $this->form_validation->set_rules('new_pwd', 'New Password', 'trim|required|min_length[4]');
        $this->form_validation->set_rules('retype_pwd', 'Retype Password', 'trim|required|min_length[4]');
        if ($this->form_validation->run() == FALSE) {
            $msg = "Invalid Login, Try again ..";
            $this->session->set_flashdata('message', $msg);
            redirect('member/myaccount/change_password');
        } else {
            $this->db->where('email', $this->session->userdata('mem_email'));
            $this->db->where('password', $this->input->post('old_pwd'));
            $query = $this->db->get('member_master');
            $result = $query->result();
            if ($query->num_rows() > 0) {
                $data = array(
                    'password' => $this->input->post('new_pwd')
                );
                $this->db->where('email', $this->session->userdata('mem_email'));
                $this->db->update('member_master', $data);
                $msg = "Password Changed successfully ....Please login again ";
                $this->session->set_flashdata('message', $msg);
                redirect('member/myaccount/change_password');
                
            } else {
                $msg = "Invalid ! Operation..";
                $this->session->set_flashdata('message', $msg);
                redirect('member/myaccount/change_password');
            }
        }
    }

}

?>
